//
//  UIBarButtonItem+Extension.swift
//  XinlangWeibo
//
//  Created by yangyinglei on 2017/3/26.
//  Copyright © 2017年 yangyinglei. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    //便利构造函数
    //可以给函数的参数提供默认值，如果调用的时候不用这个参数，那么就用默认值imageName: String? = nil
    convenience init(title: String, imageName: String? = nil, target: Any?, action: Selector) {
        //没有智能提示
        self.init()
        let btn = UIButton()
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        
        if let imgName = imageName {
            btn.setImage(UIImage(named: imgName), for: .normal)
            btn.setImage(UIImage(named: "\(imgName)_highlighted"), for: .highlighted)
        }

        //添加点击事件
        btn.addTarget(target, action: action, for: .touchUpInside)
        //设置大小
        btn.sizeToFit()
        //关联
        customView = btn
    }








}
